package com.lz.football.module.club.type
{
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.LButton;

	/**
	 * 队服颜色选择 
	 * @author Administrator
	 * 
	 */	
	public class ClothesColorMenuPanel extends Sprite implements IComponent
	{
		private var symbolSkin		:MovieClip;//皮肤
		public var selectBtn 	:LButton;//选择的btn
		public var selectType 	:int = 0;//选择类型
		/**
		 *第一种颜色 
		 */
		private var _oneBtn:LButton;
		/**
		 *第二种颜色 
		 */
		private var _twoBtn:LButton;
		/**
		 *第三种颜色 
		 */
		private var _threeBtn:LButton;
		/**
		 *第四种颜色 
		 */
		private var _fourBtn:LButton;
		/**
		 *第五种颜色 
		 */
		private var _fiveBtn:LButton;
		/**
		 *第六种颜色 
		 */
		private var _sixBtn:LButton;
		/**
		 * 第七种颜色 
		 */
		private var _seventBtn:LButton;
		
		private var _eightBtn:LButton;
		
		
		
		public function ClothesColorMenuPanel()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			symbolSkin = view as MovieClip;
			_oneBtn = new LButton(symbolSkin.oneColorBtn);
			_oneBtn.enable = true;
			_twoBtn = new LButton(symbolSkin.twoColorBtn);
			_twoBtn.enable = true;
			_threeBtn = new LButton(symbolSkin.threeColorBtn);
			_threeBtn.enable = true;
			_fourBtn = new LButton(symbolSkin.fourColorBtn);
			_fourBtn.enable = true;
			_fiveBtn = new LButton(symbolSkin.fiveColorBtn);
			_fiveBtn.enable = true;
			_sixBtn = new LButton(symbolSkin.sixColorBtn);
			_sixBtn.enable = true;
			_seventBtn = new LButton(symbolSkin.seventColorBtn);
			_seventBtn.enable = true;
			_eightBtn = new LButton(symbolSkin.eightColorBtn);
			_eightBtn.enable = true;
			addEvtListener();
//			selectTabButton(_oneBtn);
//			selectType = ColorMenuType.ONE_CONST;
			
		}
	
		
		/**
		 *按钮设置成可选状态 
		 * @param $btn
		 * 
		 */
		private function showUP($btn:LButton):void
		{
			$btn.setStatus(LButton.UP);
			$btn.enable = true;
			$btn.filter = false;
		}
		/**
		 * 设置选中状态
		 * @param $type
		 * 
		 */
		public function setSelectStatus($type:int):void
		{
			if(selectBtn)
			{
				selectBtn.enable = true;
				selectBtn.setStatus(LButton.UP);
			}
			selectType = $type;
			switch($type)
			{
				case ColorMenuType.ONE_CONST:
					selectTabButton(_oneBtn);
					break;
				case ColorMenuType.TWO_CONST:
					selectTabButton(_twoBtn);
					break;
				case ColorMenuType.THREE_CONST:
					selectTabButton(_threeBtn);
					break;
				case ColorMenuType.FOUR_CONST:
					selectTabButton(_fourBtn);
					break;
				case ColorMenuType.FIVE_CONST:
					selectTabButton(_fiveBtn);
					break;
				case ColorMenuType.SIX_CONST:
					selectTabButton(_sixBtn);
					break;
				case ColorMenuType.SEVEN_CONST:
					selectTabButton(_seventBtn);
					break;
				case ColorMenuType.EIGHT_CONST:
					selectTabButton(_eightBtn);
			}
		}
		/**
		 *选择某个tab button 
		 * @param lBtn
		 * 
		 */		
		public function selectTabButton(lBtn :LButton):void
		{
			selectBtn = lBtn;
			if(selectBtn)
			{
				selectBtn.enable = false;
				selectBtn.setStatus(LButton.SELECT);
			}
		}
		/**
		 *设置按钮为可选状态 
		 * 
		 */
		public function upButton():void
		{
			selectBtn.setStatus(LButton.UP);
			selectBtn.enable = true;
		}
		public function addEvtListener():void
		{
			_oneBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_twoBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_threeBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_fourBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_fiveBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_sixBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_seventBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_eightBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
		}
		private function onClickHandler(event:MouseEvent):void
		{
			if(selectBtn)
			{
				selectBtn.enable = true;
				selectBtn.setStatus(LButton.UP);
			}
			selectTabButton( event.target as LButton ); 
			switch(selectBtn)
			{
				case _oneBtn:
					selectType = ColorMenuType.ONE_CONST;
					break;
				case _twoBtn:
					selectType = ColorMenuType.TWO_CONST;
					break;
				case _threeBtn:
					selectType = ColorMenuType.THREE_CONST;
					break;
				case _fourBtn:
					selectType = ColorMenuType.FOUR_CONST;
					break;
				case _fiveBtn:
					selectType = ColorMenuType.FIVE_CONST;
					break;
				case _sixBtn:
					selectType = ColorMenuType.SIX_CONST;
					break;
				case _seventBtn:
					selectType = ColorMenuType.SEVEN_CONST;
					break;
				case _eightBtn:
					selectType = ColorMenuType.EIGHT_CONST;
					break;
					
			}
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		public function removeEvtListener():void
		{
			_oneBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_twoBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_threeBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_fourBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_fiveBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_sixBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_seventBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_eightBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
		}
		
		public function destroyView():void
		{
			removeEvtListener();
			_oneBtn.enable = false;
			_twoBtn.enable = false;
			_threeBtn.enable = false;
			_fourBtn.enable = false;
			_fiveBtn.enable = false;
			_sixBtn.enable = false;
			_seventBtn.enable = false;
			_eightBtn.enable = false;
			_oneBtn = null;
			_twoBtn= null;
			_threeBtn= null;
			_fourBtn= null;
			_fiveBtn= null;
			_sixBtn= null;
			_seventBtn= null;
			_eightBtn= null;
		}
		
	}
}